package jp.co.cos.ittrick.channel.controller.client;

import java.util.List;

import jp.co.cos.ittrick.channel.meta.ChannelModelMeta;
import jp.co.cos.ittrick.channel.model.ChannelModel;
import jp.co.cos.ittrick.channel.service.ChannelService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class GetChannelListController extends Controller {

    private ChannelService channelService;

    public GetChannelListController() {
        channelService = new ChannelService();
    }

    @Override
    protected Navigation run() throws Exception {

        List<ChannelModel> channelList = channelService.getAll();

        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        Object[] entityArray = channelList.toArray();
        response.getWriter().println(ChannelModelMeta.get().modelsToJson(entityArray));
        response.flushBuffer();

        return null;
    }

}
